﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebClient
{
    public partial class Viewcart : System.Web.UI.Page
    {
        string scart = "<div></div>";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack) {
                if (Session["users"] != null)
                {
                    DTO.Users item =(DTO.Users)Session["users"];
                    viewCartUser(item.id);
                }
            }
        }

        private void viewCartUser(long cusId) {
            WebData db = new WebData();
            List<DTO.Cartdetail> list = new List<DTO.Cartdetail>();
            foreach (DTO.Cart cart in db.getCartByUsers(cusId)) { 
                foreach(DTO.Cartdetail detail in db.GetAllByCartDetailByCartId(cart.id)){
                    list.Add(detail);
                }
            }
            this.grdDs.DataSource = list;
            this.grdDs.DataBind();
        }

        private void LoadCartDetail(long cartId)
        {
            WebData db = new WebData();
            this.grdDs.DataSource = db.GetAllByCartDetailByCartId(cartId);
            this.grdDs.DataBind();
        }
    }
}